package edu.zcmu.seckill.scheduled;

import edu.zcmu.seckill.service.ProductService;
import edu.zcmu.seckill.service.SeckillProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Author: tang
 * @Date: 2022/01/18/13:21
 * @Description:
 */
@Component
@EnableAsync
@EnableScheduling
@Slf4j
public class SeckillScheduled {
    @Autowired
    RedisTemplate redisTemplate;


    @Autowired
    ProductService productService;
    @Autowired
    SeckillProductService service;
    /**
     * @Author tang
     * @Date 2022/1/18
     * @Description: 每天晚上2点执行上架秒杀产品
     */
    @Async
    @Scheduled(cron = "0 0 2 * * ?")//  每天晚上2点执行
    public void uploadSeckill(){
        log.info("上架产品定时任务启动--");
//        productService.uploadProductCache();
        service.uploadSeckillProductCache();
        log.info("上架产品完成--");
    }
}